package com.kx.springmvc.convert;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义格式化Date类
 * @ClassName MyDateConvert
 * @Author Sun
 * @Date 2021/5/20 19:04
 */
@Component
public class MyDateConvert implements Converter<String, Date> {
   private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    @Override
    public Date convert(String source) {
        try {
            Date date = sdf.parse(source);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
